home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Lib / util / utctime.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  1.3 KB  |  91 lines

  1. /* utctime: utctime functions */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Lib/util/RCS/utctime.c,v 6.0 1991/12/18 20:25:18 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Lib/util/RCS/utctime.c,v 6.0 1991/12/18 20:25:18 jpo Rel $
  9.  *
  10.  * $Log: utctime.c,v $
  11.  * Revision 6.0  1991/12/18  20:25:18  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include "util.h"
  19. #include <isode/psap.h>
  20.  
  21. UTC    time_t2utc ();
  22. time_t    utc2time_t ();
  23. UTC    utcdup ();
  24. time_t    time ();
  25.  
  26. UTC    time_t2utc(t)
  27. time_t    t;
  28. {
  29.     struct tm *tm;
  30.     struct UTCtime uts;
  31.  
  32.     tm = gmtime (&t);
  33.     tm2ut (tm, &uts);
  34.     return utcdup(&uts);
  35. }
  36.  
  37.  
  38. UTC     utclocalise(utc)
  39. UTC    utc;
  40. {
  41.     time_t    ti;
  42.     struct tm    *tm;
  43.     struct UTCtime    uts;
  44.  
  45.     ti = utc2time_t(utc);
  46.     tm = localtime(&ti);
  47.     tm2ut (tm, &uts);
  48. #ifdef sun
  49.     if (tm -> tm_gmtoff != 0) {
  50.         uts.ut_flags |= UT_ZONE;
  51.         uts.ut_zone = tm -> tm_gmtoff / 60;
  52.     }
  53. #endif
  54.     return utcdup(&uts);
  55. }
  56.  
  57. UTC    utcdup (utc)
  58. UTC    utc;
  59. {
  60.     UTC    ut;
  61.  
  62.     ut = (UTC) smalloc (sizeof *ut);
  63.     *ut = *utc;
  64.     return ut;
  65. }
  66.  
  67. time_t utc2time_t(utc)
  68. UTC    utc;
  69. {
  70.     struct tm *tm;
  71.     if (utc == NULLUTC)
  72.         return (time_t) 0;
  73.     if (utc -> ut_mon <= 0) utc -> ut_mon = 1; /* hack around isode bug */
  74.     tm = ut2tm (utc);
  75.     return gtime (tm);
  76. }
  77.  
  78. UTC    utcnow ()
  79. {
  80.     time_t    now;
  81.  
  82.     (void) time (&now);
  83.     return time_t2utc (now);
  84. }
  85.  
  86. int utcequ (ut1, ut2)
  87. UTC    ut1, ut2;
  88. {
  89.     return bcmp ((char *)ut1, (char *)ut2, sizeof *ut1);
  90. }
  91.